/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import java.awt.Color;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLabel;
import javax.xml.transform.Templates;
import javax.swing.JOptionPane;

// Bibliotecas nativas do projeto
import controller.Login;
import bd.login.RealizaLogin;

/**
 *
 * @author Kellison
 */
public class LoginFrm extends javax.swing.JFrame {

    /**
     * Creates new form LoginFrm
     */
    public LoginFrm() {
        Skin skin = new Skin();
        initComponents();

        lblErroSenha.setText(" ");
        lblErroUsuario.setText(" ");
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnLogin = new javax.swing.JButton();
        lblLogo = new javax.swing.JLabel();
        fldUsuario = new javax.swing.JTextField();
        fldSenha = new javax.swing.JPasswordField();
        jSeparator1 = new javax.swing.JSeparator();
        jPanel1 = new javax.swing.JPanel();
        lblErroUsuario = new javax.swing.JLabel();
        lblErroSenha = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("SiAC - Login");
        setBackground(new java.awt.Color(255, 255, 255));
        setName("frLogin"); // NOI18N
        setResizable(false);
        setType(java.awt.Window.Type.POPUP);

        btnLogin.setText("Entrar");
        btnLogin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLoginActionPerformed(evt);
            }
        });

        lblLogo.setBackground(new java.awt.Color(86, 145, 239));
        lblLogo.setFont(new java.awt.Font("Segoe UI Light", 1, 63)); // NOI18N
        lblLogo.setForeground(new java.awt.Color(62, 130, 240));
        lblLogo.setText("SiAC");
        lblLogo.setName("lblLogo"); // NOI18N

        fldUsuario.setForeground(new java.awt.Color(51, 51, 51));
        fldUsuario.setToolTipText("Usuário");
        fldUsuario.setFocusCycleRoot(true);
        fldUsuario.setName("fldUsuario"); // NOI18N
        fldUsuario.setPreferredSize(new java.awt.Dimension(6, 25));

        fldSenha.setForeground(new java.awt.Color(51, 51, 51));
        fldSenha.setToolTipText("Senha");
        fldSenha.setPreferredSize(new java.awt.Dimension(6, 25));

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jPanel1.setBackground(new java.awt.Color(62, 130, 240));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 25, Short.MAX_VALUE)
        );

        lblErroUsuario.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        lblErroUsuario.setForeground(new java.awt.Color(204, 0, 0));
        lblErroUsuario.setText("erro_usuario");
        lblErroUsuario.setName("lblErroUsuario"); // NOI18N

        lblErroSenha.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        lblErroSenha.setForeground(new java.awt.Color(204, 0, 0));
        lblErroSenha.setText("erro_senha");
        lblErroSenha.setName("lblerroSenha"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(lblLogo, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(fldUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(fldSenha, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblErroUsuario)
                            .addComponent(lblErroSenha)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addComponent(btnLogin)))
                .addContainerGap(14, Short.MAX_VALUE))
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(49, 49, 49)
                                .addComponent(lblLogo, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(28, 28, 28))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(fldUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblErroUsuario)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(fldSenha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblErroSenha)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                        .addComponent(btnLogin))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        btnLogin.getAccessibleContext().setAccessibleName("btnLogin");
        lblLogo.getAccessibleContext().setAccessibleName("lblLogo");
        lblLogo.getAccessibleContext().setAccessibleDescription("");
        fldUsuario.getAccessibleContext().setAccessibleName("fldUsuario");
        fldSenha.getAccessibleContext().setAccessibleName("fldSenha");

        getAccessibleContext().setAccessibleDescription("Login para os sistema.");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnLoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLoginActionPerformed
        // TODO add your handling code here:
        
        Login control = new Login(fldUsuario.getText(), fldSenha.getPassword().toString(), fldSenha.getPassword().length);
        boolean verTamanhoSenha = control.verificaTamanhoUsuario();
        boolean verTamanhoUsuario = control.verificaTamanhoSenha();
              
                
        if (control.verificaVazios()) {
            
            if ( verTamanhoSenha == false) {
                lblErroUsuario.setText("Tamanho inválido.");
            }
            else{
                lblErroUsuario.setText(" ");
            }
            if ( verTamanhoUsuario == false) {
                lblErroSenha.setText("Tamanho inválido.");
            }
            else{
                lblErroSenha.setText(" ");
            }
            
            if(verTamanhoSenha && verTamanhoUsuario){
                new RealizaLogin(fldUsuario.getText(), fldSenha.getPassword().toString()).BuscaDados();
            }
        }
        else{
            JOptionPane.showMessageDialog(rootPane, "Preencha os campos antes de tentar logar.");
        }

    }//GEN-LAST:event_btnLoginActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new LoginFrm().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnLogin;
    private javax.swing.JPasswordField fldSenha;
    private javax.swing.JTextField fldUsuario;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel lblErroSenha;
    private javax.swing.JLabel lblErroUsuario;
    private javax.swing.JLabel lblLogo;
    // End of variables declaration//GEN-END:variables
}
